package com.maoye.ossp.biz.contract.controller;

/**
 * 
 * 字段修改记录管理Controller
 * @author liuw
 * @date 2013-12-16
 * @version 1.0
 */
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.maoye.ossp.biz.contract.entity.IntentModifies;
import com.maoye.ossp.biz.contract.service.IntentModifiesService;
import com.maoye.ossp.common.web.BaseController;

@Controller
@RequestMapping(value = "biz/fieldRecord/fieldmanager/")
public class IntentModifiesController extends BaseController {
	
	@Resource
	IntentModifiesService service;
	
	@RequestMapping(value="getList")
	public String getList(Model model){
		Map<String, Object> map = new HashMap<String, Object>();
		List<IntentModifies> list = service.getList(map);
		model.addAttribute("list", list);
		return "";
	}
	
	@RequestMapping(value="get")
	@ResponseBody
	public Map<String, Object> get(String attributeName){
		Map<String, Object> map = new HashMap<String, Object>();
		IntentModifies intentModifies = service.getByfieldName(attributeName);
		map.put("intentModifies", intentModifies);
		if(intentModifies != null)
			map.put("updateTime", new SimpleDateFormat("yyyy-MM-dd hh:MM:ss").format(intentModifies.getUpdateTime()));
		return map;
	}
	
	@RequestMapping(value="create")
	public String create(IntentModifies intentModifies, Model model){
		intentModifies.setId(idGenerator.getUId());
		intentModifies.setUpdateBy("admin");
		intentModifies.setUpdateTime(new Date());
		service.delByFieldName(intentModifies.getAttributeName());
		service.create(intentModifies);
		return "redirect:get?fieldName="+intentModifies.getUpdateValue();
	}
}
